package com.crane.oss.sports;

import com.crane.common.framework.http.apache.HttpClientUtils;
import com.crane.common.framework.http.apache.HttpResult;
import com.crane.oss.xunfei.req.QueryOpenCourseDetailClassReq;
import com.crane.oss.xunfei.req.QueryOpenCourseDetailTeacherReq;
import com.crane.oss.xunfei.req.QueryOpenCourseOverallReq;
import com.crane.oss.xunfei.resp.*;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class XunFeiOpenCourseApiService extends XunFeiApiService {
    /**
     * 开课情况统计
     */
    public ApiSingleResponse<OpenCourseOverallResp> getOpenCourseOverall(QueryOpenCourseOverallReq request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/opencourse/info/overall",params);
        if(httpResult.isSuccess()){
            ApiSingleResponse<OpenCourseOverallResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse<OpenCourseOverallResp>>(){});
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }

    /**
     * 开课情况图标统计
     */
    public ApiListResponse<OpenCourseSituationResp> getOpenCourseSituation(QueryOpenCourseOverallReq request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/opencourse/info/situation",params);
        if(httpResult.isSuccess()){
            ApiListResponse<OpenCourseSituationResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<OpenCourseSituationResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    /**
     * 获取班级开课列表
     */
    public ApiListResponse<OpenCourseDetailClassResp> getOpenCourseDetailClass(QueryOpenCourseDetailClassReq request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/opencourse/info/detail/class",params);
        if(httpResult.isSuccess()){
            ApiListResponse<OpenCourseDetailClassResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<OpenCourseDetailClassResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    /**
     * 获取老师开课列表
     */
    public ApiListResponse<OpenCourseDetailTeacherResp> getOpenCourseDetailTeacher(QueryOpenCourseDetailTeacherReq request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/opencourse/info/detail/teacher",params);
        if(httpResult.isSuccess()){
            ApiListResponse<OpenCourseDetailTeacherResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<OpenCourseDetailTeacherResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    public static void main(String[] args) {
        XunFeiOpenCourseApiService xunFeiApiService=new XunFeiOpenCourseApiService();

        QueryOpenCourseDetailClassReq queryIndexCourseStatisticReq=new QueryOpenCourseDetailClassReq();
        queryIndexCourseStatisticReq.setClassId("1");
        queryIndexCourseStatisticReq.setTime("202205");
        queryIndexCourseStatisticReq.setPage(1);
        queryIndexCourseStatisticReq.setLimit(1);
        System.out.println(xunFeiApiService.getOpenCourseDetailClass(queryIndexCourseStatisticReq,"87", null,"3"));


//        QueryOpenCourseDetailTeacherReq queryOpenCourseDetailTeacherReq=new QueryOpenCourseDetailTeacherReq();
//        queryOpenCourseDetailTeacherReq.setTeacherId("8ae76eeb79dc4e0aaa13f489296ac008");
//        queryOpenCourseDetailTeacherReq.setBeginTime(1648771200000L);
//        queryOpenCourseDetailTeacherReq.setEndTime(1651363200000L);
//        queryOpenCourseDetailTeacherReq.setPage(0);
//        queryOpenCourseDetailTeacherReq.setLimit(2);
//        System.out.println(xunFeiApiService.getOpenCourseDetailTeacher(queryOpenCourseDetailTeacherReq,"87", null,"3"));
    }
}

